package vn.edu.saigontech.ncms.model.depr;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.OptimisticLockType;

import vn.edu.saigontech.ncms.model.BaseEntity;
import vn.edu.saigontech.ncms.model.info.OfferingMember;

@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true, optimisticLock = OptimisticLockType.ALL)
@Table(name = "ncms_midterm_test")
@MappedSuperclass
@SuppressWarnings("serial")
public class MidtermTestDepr extends BaseEntity {
	
	public static final double WEIGHT = 0.3;
	
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "offering_member_id")
	private OfferingMember offeringMember;
	
	@Column(name = "listening")
	private Double listening;
	
	@Column(name = "pronunciation")
	private Double pronunciation;
	
	@Column(name = "grammar")
	private Double grammar;
	
	@Column(name = "reading")
	private Double reading;
	
	@Column(name = "writing")
	private Double writing;
	
	@Column(name = "comment", length = 4000)
	private String comment;
	
	@Transient
	public Double getTotal() {
		try {
			double total = this.listening + this.grammar + this.reading + this.writing;
			if((total % 0.5) == 0) return total;
			return (double)Math.round(total);
		}
		catch(Exception ex) {}
		return null;
	}
	
	@Transient
	public Double getConvertedScore() {
		Double total = this.getTotal();
		if(total == null) return null;
		return total * WEIGHT;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public Double getListening() {
		return listening;
	}

	public void setListening(Double listening) {
		this.listening = listening;
	}

	public Double getReading() {
		return reading;
	}

	public void setReading(Double reading) {
		this.reading = reading;
	}

	public Double getGrammar() {
		return grammar;
	}

	public void setGrammar(Double grammar) {
		this.grammar = grammar;
	}

	public Double getWriting() {
		return writing;
	}

	public void setWriting(Double writing) {
		this.writing = writing;
	}
	
	public OfferingMember getOfferingMember() {
		return offeringMember;
	}

	public void setOfferingMember(OfferingMember offeringMember) {
		this.offeringMember = offeringMember;
	}

	public Double getPronunciation() {
		return pronunciation;
	}

	public void setPronunciation(Double pronunciation) {
		this.pronunciation = pronunciation;
	}
}